"""
抽取数据来源基类
"""
from com.data.extract import HttpRequest, Strategy, DefaultStrategy


class Extract:
    def __init__(self, http_request, strategy=DefaultStrategy.DefaultStrategy):
        assert isinstance(http_request, HttpRequest.HttpRequest)
        assert issubclass(strategy, Strategy.Strategy)

        self.http_request = http_request
        self.strategy = strategy

    def extract(self, url=""):
        if url.__len__() != 0:
            self.http_request.url = url
        return self.strategy.call(self.strategy, self.http_request)
